package com.koron.css2.systemManage.servlet;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.systemManage.service.InitService;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 初始化接口
 * @author admin
 *
 */
public class InitServlet implements ServerInterface {
	
	private static Logger log = LogManager.getLogger(InitServlet.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<String> message = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "初始化菜单列表成功", String.class);
		StringBuilder strBuil = new StringBuilder();
		try {
			InitService initService = new InitService();
			initService.initAllOperation();
			initService.initRoleOperation(factory);
		}catch(Exception ex) {
			log.error("初始化失败！！！", ex);
			message.setCode(Constant.MESSAGE_INT_FAIL);
			message.setDescription("初始化失败");
		}
		message.setData(strBuil.toString());
		return message;
	}
}
